using UnityEngine;

public class DialogueData : MonoSingleton<DialogueData>
{
    private DialogueDataSO dialogueDataSO;
    private int currentNodeId;

    public void StartDialogue(DialogueDataSO data)
    {
        dialogueDataSO = data;
        dialogueDataSO.Initialize();
        currentNodeId = 0;

    // 通过 UIManager 弹出 UI 窗口
        UIManager.Instance.OpenWindowed("UIDialogue", WindowLayer.Pop, dialogueDataSO);
    }

    public DialogueNode GetCurrentNode()
    {   
        return dialogueDataSO?.GetNode(currentNodeId);
    }

    public void SelectChoice(int index)
    {
        var node = GetCurrentNode();
        if (node != null && node.choices != null && index < node.choices.Count)
        {
            currentNodeId = node.choices[index].nextNodeId;
        }
    }

    public DialogueNode MoveNext()
    {
        return GetCurrentNode();
    }

    public bool IsDialogueOver()
    {
        return GetCurrentNode() == null;
    }
}